<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <th:block th:include="include :: header('新增合同管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>

<style>
    .fa-search{
        position: relative;
        top: -25px;
    }
    .inputInfo{
        padding-left: inherit;
    }
</style>
</head>
<body class="white-bg">

<div class="main-content">
    <ul class="nav nav-tabs">
        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 基本信息</a>
        </li>
        <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">清单列表</a>
        </li>
        <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">附件列表</a>
        </li>
    </ul>
    <div class="tab-content">
          <!--   基本信息    -->
        <div id="tab-1" class="tab-pane active">
            <div class="panel-body">
                <form class="form-horizontal" id="form-contract-add">
                    <h4 class="form-header h4">基本信息</h4>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label is-required">合同名称：</label>
                                <div class="col-sm-10">
                                    <input name="name" class="form-control" type="text" required>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">有效开始时间：</label>
                                <div class="col-sm-8">
                                    <div class="input-group date">
                                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">有效结束时间：</label>
                                <div class="col-sm-8">
                                    <div class="input-group date">
                                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group hidden">
                        <label class="col-sm-4 control-label">合同类型：</label>
                        <input name="contractType" th:value="${contractType}"  id="contractType" type="hidden">
                    </div>



                    <h4 class="form-header h4">甲乙基本信息</h4>
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方名称：</label>
                                <div class="col-sm-8">
                                    <input name="owner" class="form-control inputInfo" type="text" onclick="selectOwner(1)">
                                    <input name="ownerDeptId" class="form-control inputInfo hidden" type="text" >
                                    <i class="fa fa-search"></i>
                                    </input>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方名称：</label>
                                <div class="col-sm-8">
                                    <input name="buy" class="form-control inputInfo" type="text" onclick="selectBuy(2)" >
                                    <input name="buyDeptId" class="form-control inputInfo hidden" type="text" >
                                    <i class="fa fa-search"></i>
                                    </input>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方联系人：</label>
                                <div class="col-sm-8">
                                    <input name="ownerName" class="form-control" readonly type="text">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方联系人：</label>
                                <div class="col-sm-8">
                                    <input name="buyName" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方联系电话：</label>
                                <div class="col-sm-8">
                                    <input name="ownerPhone" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方联系电话：</label>
                                <div class="col-sm-8">
                                    <input name="buyPhone" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方地址：</label>
                                <div class="col-sm-8">
                                    <input name="ownerAddress" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方地址：</label>
                                <div class="col-sm-8">
                                    <input name="buyAddress" class="form-control" readonly type="text">
                                </div>
                            </div>
                        </div>
                    </div>
                    <h4 class="form-header h4">合同内容</h4>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">合同内容：</label>
                                <div class="col-sm-10">
                                    <input type="hidden" class="form-control" name="content">
                                    <div class="summernote" id="content"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注：</label>
                                <div class="col-sm-10">
                                    <input name="remark" class="form-control" type="text">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!--   end 基本信息    -->

        <!--   清单列表    -->
        <div id="tab-2" class="tab-pane">
            <div class="panel-body">
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="chooseProduct()" >
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="removeQingDan()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table-qingdan"></table>
                </div>
            </div>
        </div>
        <!--   end清单列表    -->

        <!--   附件列表    -->
        <div id="tab-3" class="tab-pane">
            <div class="panel-body">
                <div class="btn-group-sm" id="toolbar2" role="group">
                    <a class="btn btn-success" onclick="addContractFile()" >
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="removeRow()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table-file"></table>
                </div>
            </div>
        </div>
        <!--   end附件列表    -->
    </div>


</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
     <th:block th:include="include :: bootstrap-table-editable-js" />

    <script th:inline="javascript">
        var typeDatas = [[${@dict.getType('b_file_type')}]];
        var suffixDatas = [[${@dict.getType('b_contrack_file_suffix')}]];
        var modelType="add";//
        var contractType=localStorage.getItem("contractType");
        var prefix = ctx + "contract/contract"
        $("#form-contract-add").validate({
            focusCleanup: true
        });

        //提交合同
        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-contract-add").serialize();
                var qingdan=getAllQingDanData();
                if(!isEmptyString(qingdan)){
                    data=data+"&params[qingdan]="+getAllQingDanData()+"&params[contractFile]="+getAllContractFileData();
                    $.operate.save(prefix + "/add", data);
                }

            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });



        //文本编辑器
        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });


    </script>


<script th:src="@{/js/contract/contractProduct/congractProduct.js}"></script>
<script th:src="@{/js/contract/contractFile/contractFile.js}"></script>
<script th:src="@{/js/contract/chooseParter.js}"></script>
</body>
</html>
